package com.jiang.专题.回溯.Q77;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/04/28 16:08
 */
public class Solution {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        for (int i = 1; i <= n - k + 1; i++) {
            dfs(i, n, k, new ArrayList<>(List.of(i)));
        }
        return res;
    }
    private void dfs(int start, int n, int k, List<Integer> list)  {
        int size = list.size();

        if (size == k) {
            res.add(new ArrayList<>(list));
            return;
        }
        for (int i = start + 1; i <= n; i++) {
            list.add(i);
            dfs(i, n, k, list);
            list.remove(list.size() - 1);
        }
    }
}
